#include<iostream>
using namespace std;
#define MAXSIZE 100
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
int m; //m为操作次数
typedef struct
{ ElemType *elem;
  int length;
}SqList;//顺序表

void CreateList(SqList &L, int n){
    L.elem = new ElemType[MAXSIZE];
    L.length = n;
    for(int i = 0; i < n; ++i){
        cin >> L.elem[i];
    }
}

void MergeList_Sq(SqList LA, SqList LB, SqList &LC){
    LC.elem = new ElemType[LA.length+LB.length];
    LC.length = 0;
    int i = 0, j = 0;
    while(i < LA.length && j < LB.length){
        if(LA.elem[i] <= LB.elem[j]){
            LC.elem[LC.length++] = LA.elem[i++];
        }else{
            LC.elem[LC.length++] = LB.elem[j++];
        }
    }
    while(i < LA.length){
        LC.elem[LC.length++] = LA.elem[i++];
    }
    while(j < LB.length){
        LC.elem[LC.length++] = LB.elem[j++];
    }
}

void Out_list(SqList L){//输出顺序表
    for(int i=0; i<=L.length-1;i++)
        cout <<L.elem[i]<<' ';
    cout<<endl;
}

int main() {
    SqList LA,LB,LC;
    int j,k;
    cin >> m;     //m次操作
    while(m --) {
        char op;
        cin >> op;
        switch(op){
            case 'A'://创建顺序有序表LA
                cin>>j;
                CreateList(LA, j);
                Out_list(LA);
                break;
            case 'B'://创建顺序有序表LB
                cin>>k;
                CreateList(LB, k);
                Out_list(LB);
                break;
            case 'M'://合并顺序有序表
                MergeList_Sq(LA, LB, LC);
                Out_list(LC);
                break;
        }
    }
    return 0;
}
